package ldh.im.dto;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

public class ChunkedInfo {

    private String tag;
    private Short index;
    private Boolean isEnd;

    public ChunkedInfo(String tag, Short index, Boolean isEnd) {
        this.tag = tag;
        this.index = index;
        this.isEnd = isEnd;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public short getIndex() {
        return index;
    }

    public void setIndex(short index) {
        this.index = index;
    }

    public boolean isEnd() {
        return isEnd;
    }

    public void setEnd(boolean end) {
        isEnd = end;
    }

    public byte[] toBytes() throws Exception {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
        dataOutputStream.writeUTF(tag);
        dataOutputStream.writeShort(index);
        dataOutputStream.writeBoolean(isEnd);
        return byteArrayOutputStream.toByteArray();
    }
}
